<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>xxx</title>
  <link href="./res/main.css?2" rel="stylesheet">
</head>

<body>
  <div class="wrap">
    <div>
      <p class="title">mdxx</p>
      <a class="title-help" href="https://www.xiaohongshu.com/discovery/item/673c9af30000000007025c47?source=webshare&xhsshare=pc_web&xsec_token=ABNoKxv6P-luvN2NDahC0JWkyMt-1Qcqzgu7a8SJ4utQQ=&xsec_source=pc_share" target="_blank">查看使用教程</a>

    </div>

    <textarea id="inputText" placeholder="输入override内容" style="margin-top: 10px;"></textarea><br>
    <div  class="btn-box">
      <button class="btn" onclick="generateSRT()">生成</button>
      <button class="btn" onclick="copySRT()">复制</button>
    </div>
    <div id="info">无操作...</div>

    <textarea id="outputSRT" placeholder="结果" style="margin-top: 10px;"></textarea>
  </div>
  <script>
    const orgText = document.getElementById('inputText');
    const outputSRT = document.getElementById('outputSRT');
    const infoSpan = document.getElementById('info');

    // orgText.addEventListener('input', () => {
    //   const currentValue = orgText.value;
    //   localStorage.setItem('inputText', currentValue);
    // });

    function copySRT() {
      generateSRT()

      navigator.clipboard.writeText(outputSRT.value)
        .then(() => {
          showInfo("已复制")
        })
        .catch(err => {
          showInfo("复制失败")
          console.error('复制失败：', err);
        });
    }

    function generateSRT() {
      let regex = /[ 	]*\["workshop-(\d+)"]/g;
      let str = ""
      const data = orgText.value;
      for (const match of data.matchAll(regex)) {
        str += "ServerModSetup(\"" + match[1] + "\")\n"
      }
      outputSRT.value = str;

    }

    function showInfo(msg) {
      infoSpan.textContent = msg
    }

  </script>
</body>

</html>
